package com.qq.API_日期与时间.JDK8;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;

//LocalDateTime localDateTime = LocalDateTime.now();//日期时间对象
//LocalDateTime localDateTime = LocalDateTime.of(2022,11,22,15,09,59);调用静态方法，指定日期时间创建对象
//					LocalDateTime.of(LocalDate a, LocalDate b),可以传日期时间对象来创建
//LocalDateTime nowDateTime = LocalDateTime.from(Temporal);//提取来自其他日期时间对象的日期时间，来创建对象


public class API_LocalDateTime {
    public static void main(String[] args) {
        //1.创建日期时间对象
        LocalDateTime nowDateTime = LocalDateTime.now();
        System.out.println("今天是：" + nowDateTime);
        //整合了日期和时间对象的所有方法
        System.out.println(nowDateTime.getYear());//年
        System.out.println(nowDateTime.getMonthValue());//月
        System.out.println(nowDateTime.getDayOfMonth());//日
        System.out.println(nowDateTime.getHour());//时
        System.out.println(nowDateTime.getMinute());//分
        System.out.println(nowDateTime.getSecond());//秒
        System.out.println(nowDateTime.getNano());//纳秒,1秒 == 1000毫秒  == 1000000微秒 == 1000000000纳秒
        System.out.println("-------------");
//        System.out.println(nowDateTime.from(LocalDate.now()));
        //一年的第几天
        System.out.println("dayOfYear：" + nowDateTime.getDayOfYear());
        //星期
        System.out.println(nowDateTime.getDayOfWeek());//枚举
        System.out.println(nowDateTime.getDayOfWeek().getValue());//转int
        //月份
        System.out.println(nowDateTime.getMonth());//枚举
        System.out.println(nowDateTime.getMonth().getValue());//转int
        System.out.println(nowDateTime.getMonthValue());
       
        //【日期时间对象】 可以转换成 【日期或时间对象】 ，
        LocalDate ld = nowDateTime.toLocalDate();
        System.out.println(ld);
        LocalTime lt = nowDateTime.toLocalTime();
        System.out.println(lt);
        System.out.println(lt.getHour());
        //【日期或时间】对象也能提取【日期时间对象】创建对象
        LocalTime lt2 = LocalTime.from(nowDateTime);
        LocalDate ld2 = LocalDate.from(nowDateTime);
        System.out.println(ld2 + "哈哈" +lt2);
        
        System.out.println("---------------");
        
        //2.创建指定日期时间对象（整合了日期和时间对象的指定功能--如月份可枚举类型和 时分秒的重载）
        System.out.println(LocalDateTime.of(1991, 11, 11, 8, 20));
        System.out.println(LocalDateTime.of(1991, Month.NOVEMBER, 11, 8, 20));
        System.out.println(LocalDateTime.of(1991, 11, 11, 8, 20, 30));
        System.out.println(LocalDateTime.of(1991, Month.NOVEMBER, 11, 8, 20, 30));
        System.out.println(LocalDateTime.of(1991, 11, 11, 8, 20, 30, 150));
        System.out.println(LocalDateTime.of(1991, Month.NOVEMBER, 11, 8, 20, 30, 150));
        //也可以传日期时间对象来创建
        LocalDateTime.of(LocalDate.now(), LocalTime.now());

    }
}
